package com.pty.mercuryservice.component;

import com.pty.mercuryservice.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by pty on 2017/12/25
 */
@Slf4j
@Component
public class MqSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send() {
        String msg = "你好，给你发消息了。";
        log.info("开始发送mq消息>>{}", msg);
        amqpTemplate.convertAndSend("queue", msg);
    }

    public void sendBean(UserDTO userDTO) {
        log.info("开始发送消息，user >> {}", userDTO.toString());
        amqpTemplate.convertAndSend("queueBean", userDTO);
    }

    public void sendTopicMsg() {
        String msg = "你好，给你发消息了,是Topic哦。";
        log.info("开始发送mq消息>>{}", msg);
        amqpTemplate.convertAndSend("exchange", "topic.message", msg);
    }

    public void sendTopicMsgs() {
        String msg = "你好，给你发消息了,是Topic.Messages哦。";
        log.info("开始发送mq消息>>{}", msg);
        amqpTemplate.convertAndSend("exchange", "topic.messages", msg);
    }
}
